<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

<div id="formArea">
	<table class="table">
		<tr>
			<td><label class="label required">公司名称</label></td>
			<td><input type="text" class="input" name="name" autocomplete="off" placeholder="请输入公司名称"/></td>
		</tr>
		<tr>
			<td><label class="label">联系人：</label></td>
			<td><input type="text" class="input" name="contact" autocomplete="off" placeholder="请输入联系人"/></td>
		</tr>
		<tr>
			<td><label class="label">联系电话：</label></td>
			<td><input type="text" class="input" name="contactPhone" autocomplete="off" placeholder="请输入联系电话"/></td>
		</tr>

	</table>
</div>


<script>

var requestParams = app.getRequestParams();

$(function () {

    if(requestParams.id){
        $('#formArea').append('<input type="hidden" name="id"/>');
        app.resetForm(JSON.parse(decodeURIComponent(requestParams.data)));
	}

});


app.getOkBtn().click(function(){
	if( !checkForm() ){
		return;
	}
    var url = 'company/insert';
    var data = app.serializeForm();

    if(requestParams.id){
        url = 'company/update'
    }
    if( requestParams.parentId ){
        data.parentId = requestParams.parentId;
	}
    app.request({
        url:url,
        data:data,
        success:function (resp) {
            if( resp.result==0 ){
                app.closeLastWindow();
                app.message(parent.layer,'操作成功');
                parent.$("#table").treegrid("reload");
            }else{
                app.message(parent.layer,'操作失败【'+app.getErrorMsg(resp)+'】',2);
            }
        }
    });

});

function checkForm(){
    var checkOptions = [
        {type:'input',name:'name',verify:[{type:'required'},{type:'length',value:20}]},
        {type:'input',name:'contact',verify:[{type:'length',value:5}]},
        {type:'input',name:'contactPhone',verify:[{type:'length',value:20}]}
	];
	return app.checkForm(checkOptions);
}

</script>

</body>
</html>